<?php
/* @var $this ScheduleController */
/* @var $week week number*/
/* @var $year year number*/
/* @var $days array of weekday=>date*/

if (Yii::app()->request->isAjaxRequest){
	Yii::app()->clientScript->scriptMap['jquery.js'] = false;
	Yii::app()->clientScript->scriptMap['jquery.min.js'] = false;	
	Yii::app()->clientScript->scriptMap['jquery.ba-bbq.js'] = false;	
	Yii::app()->clientScript->scriptMap['tableAjaxHandler.js'] = false;	
} 


?>

<br>

<center>

<h3>Viewing Week <?php echo $week; ?> -  <?php echo $year; ?>   </h3>


	<?php
	echo CHtml::link('<-Prev Week', 
					 Yii::app()->createUrl('/schedule/FTEReporting' , 
										   array('week'=> ($week!=1)? $week-1 : 52, 
											     'year'=> ($week!=1)? $year : $year-1,
												)
										  ), 
					 array('title' => 'Previous Week','style'=>'color:#339900;')
				); 	
	?>
	
	&nbsp | &nbsp
	
	<?php
	echo CHtml::link('Next Week->', 
					 Yii::app()->createUrl('/schedule/FTEReporting' , 
										   array('week'=> ($week!=52)? $week+1 : 1, 
												 'year'=>($week!=52)? $year : $year+1,
												)
										  ), 
					 array('title' => 'Next Week','style'=>'color:#339900;')
				); 	
	?>
	
<br>	
<br>	

<center>

<!--  RESULT VISOR   -->
<div id="resultVisor"> </div>

	<div class="swapTable" >
		<table>
			<tr>
				<th> 
					Weekday
				</th>
				
				<th>
					CSE Count
				</th>
			
			</tr>
			
			
			<?php 
			
			$totalDaysWithCSEs = 0;
			$totalCSEForWeek= 0;
			
			foreach ($days as $keyDay=>$date):
			?>
				<tr>
					<td>
						<?php
						
						echo $keyDay; //print weekday with day number
						
						?>					
					</td>		
					
					<td>
						
						<?php
							
							$statsArray = Schedule::getTeamScheduleDateAvailabilityShiftCount(Yii::app()->user->team_id, $date, true);
							
							if($statsArray != null){
								
								$totalForDay = 0;
								
								foreach ($statsArray as $KeyRow => $row) {
									$totalForDay += $row['total'];
								}
								
								$totalDaysWithCSEs +=1;
								$totalCSEForWeek += $totalForDay;
								echo $totalForDay;
								
							} else {
								echo "<font color=red>None</font>";
							}						
							
						?>
							
						
					</td>
				
				</tr>
				
			<?php
			endforeach;
			?>
			
				<tr>
				
					<th>
						FTE Week Total =
					</th>
					
					<td>
						<?php echo $totalCSEForWeek / $totalDaysWithCSEs ; ?>
					</td>
					
				</tr>
				
			
		</table>

	</div>